package nxu.it.dao;

import com.zaxxer.hikari.HikariConfig;
import org.jdbi.v3.core.Jdbi;

import javax.sql.DataSource;

public class JdbiFactory {
    private static final String JDBC_URL = "jdbc:mysql://localhost:3306/myapp?serverTimeZone=Asia/Shanghai";
    private static final String DB_USER = "demo";
    private static final String DB_PASSWORD = "demo";
    private static DataSource ds = null;
    private static Jdbi JDBI = null;
    static{
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl(JDBC_URL);
        config.setUsername(DB_USER);
        config.setPassword(DB_PASSWORD);
        ds = new com.zaxxer.hikari.HikariDataSource(config);
    }
    public static DataSource getDataSource() {
        return ds;
    }
    public static Jdbi getJdbi() {
        if (JDBI == null) {
            JDBI = Jdbi.create(ds);
        }
        JDBI.installPlugin(new org.jdbi.v3.sqlobject.SqlObjectPlugin());
        return JDBI;
    }
}
